package com.ruoyi.web.controller.meterread;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WaterDailyUsage;
import com.ruoyi.system.domain.vo.WaterUserMeterVO;
import com.ruoyi.system.service.IWaterDailyUsageService;
import com.ruoyi.system.service.IWaterUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 日用水量Controller
 *
 * @author ruoyi
 * @date 2025-09-20
 */
@RestController
@RequestMapping("/meterread/dailyusage")
public class WaterDailyUsageController extends BaseController
{
    @Autowired
    private IWaterUserService waterUserService;
    @Autowired
    private IWaterDailyUsageService waterDailyUsageService;

    /**
     * 查询远传表档案列表
     */
    @PreAuthorize("@ss.hasPermi('meterread:dailyusage:list')")
    @GetMapping("/list")
    public TableDataInfo list(WaterUserMeterVO userMeterVO)
    {
        startPage();
        userMeterVO.setMeterType("0"); //水表类型为 远传表
        List<WaterUserMeterVO> list = waterUserService.selectWaterUserMeterList(userMeterVO);
        return getDataTable(list);
    }

    /**
     * 查询日用水量列表
     */
    @PreAuthorize("@ss.hasPermi('meterread:dailyusage:hisList')")
    @GetMapping("/hisList")
    public TableDataInfo hisList(WaterDailyUsage waterDailyUsage)
    {
        startPage();
        List<WaterDailyUsage> list = waterDailyUsageService.selectWaterDailyUsageList(waterDailyUsage);
        return getDataTable(list);
    }

    /**
     * 导出日用水量列表
     */
    @PreAuthorize("@ss.hasPermi('meterread:dailyusage:export')")
    @Log(title = "日用水量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WaterDailyUsage waterDailyUsage)
    {
        List<WaterDailyUsage> list = waterDailyUsageService.selectWaterDailyUsageList(waterDailyUsage);
        ExcelUtil<WaterDailyUsage> util = new ExcelUtil<WaterDailyUsage>(WaterDailyUsage.class);
        util.exportExcel(response, list, "日用水量数据");
    }

    /**
     * 获取日用水量详细信息
     */
    @PreAuthorize("@ss.hasPermi('meterread:dailyusage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(waterDailyUsageService.selectWaterDailyUsageById(id));
    }

    /**
     * 新增日用水量
     */
    @PreAuthorize("@ss.hasPermi('meterread:dailyusage:add')")
    @Log(title = "日用水量", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WaterDailyUsage waterDailyUsage)
    {
        return toAjax(waterDailyUsageService.insertWaterDailyUsage(waterDailyUsage));
    }

    /**
     * 修改日用水量
     */
    @PreAuthorize("@ss.hasPermi('meterread:dailyusage:edit')")
    @Log(title = "日用水量", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WaterDailyUsage waterDailyUsage)
    {
        return toAjax(waterDailyUsageService.updateWaterDailyUsage(waterDailyUsage));
    }

    /**
     * 删除日用水量
     */
    @PreAuthorize("@ss.hasPermi('meterread:dailyusage:remove')")
    @Log(title = "日用水量", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(waterDailyUsageService.deleteWaterDailyUsageByIds(ids));
    }
}
